<?php
/**
* This is controller use for public area
* @author: hungnq@younetco.com
* @version: 0.1
*/


class Contest_ShareController extends YouNet_Controller_Action{

	public function contestAction()
	{
		$id_contest		= $this->_getParam('id_contest');
		$id_page		= $this->_getParam('id_page');
		$id_user_ref	= $this->_getParam('id_user_ref');

		if( Core_Util::isSocialNetworksRequest() )
		{
			if( !empty($id_contest) && !empty($id_page) )
			{
                $shareRow = Core_Model_DbTable_Shares::getInstance()->getShareContent($id_contest, $id_page);
                $this->view->share_url		= $this->_social->getShareUrl('/contest/share/contest/id_page/' 
                         . $id_page . '/id_contest/' . $id_contest);
                $this->view->is_social_networks	= true;
                $this->view->shareRow = $shareRow;
			}
		}
		else
		{
			if( !empty($id_contest) && !empty($id_page) )
			{
				$this->_social->redirectLink($this->_social->pageUrl(array(), $id_page));
			}
			else
			{
				throw new Exception('Page Not Found', 404);
			}
		}
	}
    
    /**
     * Invite Friends via Email
     */
    public function inviteAction()
    {
        $this->disableAutoRender();
        $recipients = $this->_getParam('recipients');
        $subject = $this->_getParam('subject');
        $content = $this->_getParam('content');
        $to = array();
        foreach ($recipients as $recipient) {
            $to[] = $recipient;
        }
        $message = array(
            'subject'   =>  $subject,
            'content'   =>  $content
        );
        $mailer = new YouNet_Mail();
        $mailer->sendInvitationFriends($to, $message);
    }
}
